// pages/FileView/Personal/Personal.js

//HTTP请求request封装
var HttpRequest = require("../../../http.js");
//CBC加密 
var CryptoJS = require("../../../Crypto.js");
//RSA加密
var RSA = require("../../../rsa.js"); 
//公共方法调用
var utils = require("../../../utils/util.js"); 
Page({

  /**
   * 页面的初始数据
   */
  data: {
    personalData:'',//健康档案数据载体
  },
  //GET数据请求函数
  getReq: HttpRequest.getReq,
  //POST数据请求
  postReq: HttpRequest.postReq,      
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (e) {
   
    const that = this;
    //登录基础信息
    const login_Info = JSON.parse(wx.getStorageSync('login_Information')); 
    const headArray = wx.getStorageSync('UserLogin');
    const headers = {
      'Accept': 'application/json',
      "Content-Type": "application/x-www-form-urlencoded",
      "headMode": headArray,
      "token": login_Info.token,
    };

    //访问地址
    const url = "/resident/putonrecord/personaldetails";
    // 入参（身份证号码 ）
    const IdNumber = wx.getStorageSync('IdNumber'); 
    const data = {
      cardId: IdNumber,
    } 
    //数据字典地址
    const urls = '/allreq/dict/dictLabel';

    HttpRequest.getReq(url, data , headers, function (res,code) {
      console.log(res);
      console.log(code);
      if(code!=200){
        wx.showModal({
          title: '温馨提示',
          content: res,
          showCancel: false,
          success: function (v) {
            wx.switchTab({
              url: '../../Health/Health'
            })
          }
        })
      }
      console.log(res.familyHistory);
      var family = res.familyHistory;
      //家庭既往史
      var father;
      const typeDictUrl = '/allreq/dict/typeDict'
      const dictTypes={
        dictTypes: 'gw_family_disease',
      }
     
      HttpRequest.getReq(typeDictUrl, dictTypes, headers, function (res) {
        console.log(res);
        var dictList;
        var disVal;
        for(let i in res){
          dictList = res[i].dictList;
          for(let j in dictList){
            disVal = dictList[i].value;
          } 
        }                                                                                                           
        console.log(disVal);
        console.log(dictList);
        for (let i in family) {
          //父亲
          if (family[i].relationshipType == 1) {
            father = family[i].disease; 

            console.log(father);
          }
        }
        that.setData({
          father: father,
        })
      });
     
     



      console.log(res.healthHistory);
      var health = res.healthHistory;
      //个人既往史
      var surgeryDate;
      var traumaDate;
      var bloodDate;
      var geneticDate;
      for(let i in health){
        //手术
        if (health[i].recordType==1){ 
          surgeryDate = utils.getMyDate(health[i].occurrenceDate);
        }
        //外伤
        else if (health[i].recordType == 2){ 
          traumaDate = utils.getMyDate(health[i].occurrenceDate);
        }
        //输血
        else if (health[i].recordType == 3){ 
          bloodDate = utils.getMyDate(health[i].occurrenceDate);
        }
        //遗传
        else if (health[i].recordType == 4){ 
          geneticDate = utils.getMyDate(health[i].occurrenceDate);
        }
      }
      that.setData({
        geneticDate: geneticDate,
        bloodDate: bloodDate,
        traumaDate: traumaDate,
        surgeryDate: surgeryDate,

      })

      that.setData({
        personalData: res,
        //建档时间
        buildDate: utils.getMyDate(res.buildDate),
        //出生时间
        birthDay: utils.getMyDate(res.birthDay),
        //电话号码
        personTel: utils.personTel(res.personTel),
        //身份证号码
        cardId: utils.personTel(res.cardId),
        //联系人电话
        contactTel: utils.personTel(res.contactTel),
      }); 
      
      
      //禽畜栏
      const livestockColumn  = {
        dictType: 'gw_a_bird',
        val: res.livestockColumn ,
      }
      HttpRequest.getReq(urls, livestockColumn , headers, function (res) {
        that.setData({ livestockColumn : res, })
      });
      //流动人口
      const isFlowing  = {
        dictType: 'gw_IsFlowing_type',
        val: res.isFlowing ,
      }
      HttpRequest.getReq(urls, isFlowing , headers, function (res) {
        that.setData({ isFlowing : res, })
      });
      //饮水
      const drinkingwater  = {
        dictType: 'gw_drinking_water',
        val: res.drinkingwater ,
      }
      HttpRequest.getReq(urls, drinkingwater , headers, function (res) {
        that.setData({ drinkingwater : res, })
      });
      //厕所 
      const toilet  = {
        dictType: 'gw_toilet',
        val: res.toilet ,
      }
      HttpRequest.getReq(urls, toilet , headers, function (res) {
        that.setData({ toilet : res, })
      });
      //燃料类型 
      const fuelType  = {
        dictType: 'gw_fuel_type',
        val: res.fuelType ,
      }
      HttpRequest.getReq(urls, fuelType , headers, function (res) {
        that.setData({ fuelType : res, })
      });
      //厨房排风设施
      const kitchenExhaust  = {
        dictType: 'gw_kitchen_facilities',
        val: res.kitchenExhaust ,
      }
      HttpRequest.getReq(urls, kitchenExhaust , headers, function (res) {
        that.setData({ kitchenExhaust : res, })
      });
      //残疾情况
      const disability  = {
        dictType: 'gw_disability',
        val: res.disability ,
      }
      HttpRequest.getReq(urls, disability , headers, function (res) {
        that.setData({ disability : res, })
      });
      //暴露史
      const exposureHistory = {
        dictType: 'gw_exposure',
        val: res.exposureHistory,
      }
      HttpRequest.getReq(urls, exposureHistory, headers, function (res) {
        that.setData({ exposureHistory: res, })
      });
      //药物过敏史
      const drugallergyHistory  = {
        dictType: 'gw_drup_allergy_history',
        val: res.drugallergyHistory ,
      }
      HttpRequest.getReq(urls, drugallergyHistory , headers, function (res) {
        that.setData({ drugallergyHistory : res, })
      });
      //性别
      const gender = {
        dictType: 'gw_gender_code',
        val: res.genderCode ,
      }
      HttpRequest.getReq(urls, gender, headers, function (res) { 
        that.setData({gender: res,})
      });
      //民族
      const nation = {
        dictType: 'gw_nation',
        val: res.nationCode,
      }
      HttpRequest.getReq(urls, nation, headers, function (res) {
        that.setData({ nation: res, })
      });  
      //户籍类别
      const resType  = {
        dictType: 'gw_node_type',
        val: res.resType ,
      }
      HttpRequest.getReq(urls, resType , headers, function (res) {
        that.setData({ resType : res, })
      }); 
      //常住类型
      const hukouInd  = {
        dictType: 'gw_resident_type',
        val: res.hukouInd ,
      }
      HttpRequest.getReq(urls, hukouInd , headers, function (res) {
        that.setData({ hukouInd : res, })
      });
      //与户主关系
      const householderrelationship  = {
        dictType: 'gw_relationship_with_holder',
        val: res.householderrelationship ,
      }
      HttpRequest.getReq(urls, householderrelationship , headers, function (res) {
        that.setData({ householderrelationship : res, })
      });
      //abo血型
      const bloodType  = {
        dictType: 'gw_abo_flood_type',
        val: res.bloodType ,
      }
      HttpRequest.getReq(urls, bloodType , headers, function (res) {
        that.setData({ bloodType : res, })
      });
      //RH血型
      const rhBlood  = {
        dictType: 'gw_rh_flood_type',
        val: res.rhBlood ,
      }
      HttpRequest.getReq(urls, rhBlood , headers, function (res) {
        that.setData({ rhBlood : res, })
      });
      //文化程度
      const educationCode  = {
        dictType: 'gw_education_degree',
        val: res.educationCode ,
      }
      HttpRequest.getReq(urls, educationCode , headers, function (res) {
        that.setData({ educationCode : res, })
      });
      //职业
      const jobCode  = {
        dictType: 'gw_occupation',
        val: res.jobCode ,
      }
      HttpRequest.getReq(urls, jobCode , headers, function (res) {
        that.setData({ jobCode : res, })
      });
      //婚姻状况
      const marryStatus  = {
        dictType: 'gw_marital_status',
        val: res.marryStatus ,
      }
      HttpRequest.getReq(urls, marryStatus , headers, function (res) {
        that.setData({ marryStatus : res, })
      });
      //医疗费用支付方式
      const paymentWaystring  = {
        dictType: 'gw_payment_method',
        val: res.paymentWaystring ,
      }
      HttpRequest.getReq(urls, paymentWaystring , headers, function (res) {
        that.setData({ paymentWaystring : res, })
      });
    }) ;
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})